package Java网络编程.TCP通信程序练习.p6_多线程实现文件上传;

import java.io.*;
import java.net.Socket;

/*客户端与p5相同*/
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket s = new Socket("192.168.189.1", 2);

        //封装文本文件的数据
        BufferedReader br = new BufferedReader(new FileReader("idea_test\\client.txt"));
        //封装输出流写数据
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));

        String line;
        while ((line = br.readLine()) != null) {
            bw.write(line);
            bw.newLine();
            bw.flush();
        }

        /*结束标志，否则服务器和客户端会互相等待出现死锁*/
        //void shutdownOutput() 禁用此套接字的输出流。
        s.shutdownOutput();

        //接收服务器反馈
        BufferedReader brClient = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String data = brClient.readLine();
        System.out.println("服务器的反馈为：" + data);

        br.close();
        s.close();
    }

}
